/* 
    push:添加一个新元素到栈顶位置
    pop:删除栈顶元素,返回被移除的元素
    peek:返回栈顶元素
    isEmpty:判断栈是否为空
    size:返回栈里的元素个数
*/
import type Stack from './Stack';

class ArrayStack<T> implements Stack<T> {
  private data: T[] = [];

  push(element: T) {
    this.data.push(element);
  }

  pop(): T | undefined {
    return this.data.pop();
  }

  peek(): T | undefined {
    return this.data[this.data.length - 1];
  }

  isEmpty(): boolean {
    return this.data.length === 0;
  }

  size(): number {
    return this.data.length;
  }
}

const stack1 = new ArrayStack<string>();
stack1.push('1');
stack1.push('2');
stack1.push('3');

console.log(stack1.peek());
console.log(stack1.pop());
console.log(stack1.pop());
console.log(stack1.pop());
console.log(stack1.isEmpty());
console.log(stack1.size());

export {};
